<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="申请的用户id" prop="applyUserId">
      <el-input v-model="dataForm.applyUserId" placeholder="申请的用户id"></el-input>
    </el-form-item>
    <el-form-item label="身份证号码" prop="idCard">
      <el-input v-model="dataForm.idCard" placeholder="身份证号码"></el-input>
    </el-form-item>
    <el-form-item label="身份证正面照" prop="idCardFrontImage">
      <el-input v-model="dataForm.idCardFrontImage" placeholder="身份证正面照"></el-input>
    </el-form-item>
    <el-form-item label="身份证反面照" prop="idCardBackImage">
      <el-input v-model="dataForm.idCardBackImage" placeholder="身份证反面照"></el-input>
    </el-form-item>
    <el-form-item label="驾驶证照片" prop="driverLicenseImage">
      <el-input v-model="dataForm.driverLicenseImage" placeholder="驾驶证照片"></el-input>
    </el-form-item>
    <el-form-item label="车牌号" prop="licensePlate">
      <el-input v-model="dataForm.licensePlate" placeholder="车牌号"></el-input>
    </el-form-item>
    <el-form-item label="车辆颜色" prop="color">
      <el-input v-model="dataForm.color" placeholder="车辆颜色"></el-input>
    </el-form-item>
    <el-form-item label="车辆描述信息" prop="description">
      <el-input v-model="dataForm.description" placeholder="车辆描述信息"></el-input>
    </el-form-item>
    <el-form-item label="车辆的图片【字符串数组使用,分割】" prop="carImages">
      <el-input v-model="dataForm.carImages" placeholder="车辆的图片【字符串数组使用,分割】"></el-input>
    </el-form-item>
    <el-form-item label="申请状态【0  未审批 1 申请通过  2 申请未通过】" prop="status">
      <el-input v-model="dataForm.status" placeholder="申请状态【0  未审批 1 申请通过  2 申请未通过】"></el-input>
    </el-form-item>
    <el-form-item label="审批用户的id" prop="approvalUserId">
      <el-input v-model="dataForm.approvalUserId" placeholder="审批用户的id"></el-input>
    </el-form-item>
    <el-form-item label="审批用户的姓名" prop="approvalUserTrueName">
      <el-input v-model="dataForm.approvalUserTrueName" placeholder="审批用户的姓名"></el-input>
    </el-form-item>
    <el-form-item label="不通过的原因" prop="noPassReason">
      <el-input v-model="dataForm.noPassReason" placeholder="不通过的原因"></el-input>
    </el-form-item>
    <el-form-item label="创建时间" prop="createTime">
      <el-input v-model="dataForm.createTime" placeholder="创建时间"></el-input>
    </el-form-item>
    <el-form-item label="更新时间" prop="updateTime">
      <el-input v-model="dataForm.updateTime" placeholder="更新时间"></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          id: 0,
          applyUserId: '',
          idCard: '',
          idCardFrontImage: '',
          idCardBackImage: '',
          driverLicenseImage: '',
          licensePlate: '',
          color: '',
          description: '',
          carImages: '',
          status: '',
          approvalUserId: '',
          approvalUserTrueName: '',
          noPassReason: '',
          createTime: '',
          updateTime: ''
        },
        dataRule: {
          applyUserId: [
            { required: true, message: '申请的用户id不能为空', trigger: 'blur' }
          ],
          idCard: [
            { required: true, message: '身份证号码不能为空', trigger: 'blur' }
          ],
          idCardFrontImage: [
            { required: true, message: '身份证正面照不能为空', trigger: 'blur' }
          ],
          idCardBackImage: [
            { required: true, message: '身份证反面照不能为空', trigger: 'blur' }
          ],
          driverLicenseImage: [
            { required: true, message: '驾驶证照片不能为空', trigger: 'blur' }
          ],
          licensePlate: [
            { required: true, message: '车牌号不能为空', trigger: 'blur' }
          ],
          color: [
            { required: true, message: '车辆颜色不能为空', trigger: 'blur' }
          ],
          description: [
            { required: true, message: '车辆描述信息不能为空', trigger: 'blur' }
          ],
          carImages: [
            { required: true, message: '车辆的图片【字符串数组使用,分割】不能为空', trigger: 'blur' }
          ],
          status: [
            { required: true, message: '申请状态【0  未审批 1 申请通过  2 申请未通过】不能为空', trigger: 'blur' }
          ],
          approvalUserId: [
            { required: true, message: '审批用户的id不能为空', trigger: 'blur' }
          ],
          approvalUserTrueName: [
            { required: true, message: '审批用户的姓名不能为空', trigger: 'blur' }
          ],
          noPassReason: [
            { required: true, message: '不通过的原因不能为空', trigger: 'blur' }
          ],
          createTime: [
            { required: true, message: '创建时间不能为空', trigger: 'blur' }
          ],
          updateTime: [
            { required: true, message: '更新时间不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.id = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.id) {
            this.$http({
              url: this.$http.adornUrl(`/order/apply/info/${this.dataForm.id}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.applyUserId = data.apply.applyUserId
                this.dataForm.idCard = data.apply.idCard
                this.dataForm.idCardFrontImage = data.apply.idCardFrontImage
                this.dataForm.idCardBackImage = data.apply.idCardBackImage
                this.dataForm.driverLicenseImage = data.apply.driverLicenseImage
                this.dataForm.licensePlate = data.apply.licensePlate
                this.dataForm.color = data.apply.color
                this.dataForm.description = data.apply.description
                this.dataForm.carImages = data.apply.carImages
                this.dataForm.status = data.apply.status
                this.dataForm.approvalUserId = data.apply.approvalUserId
                this.dataForm.approvalUserTrueName = data.apply.approvalUserTrueName
                this.dataForm.noPassReason = data.apply.noPassReason
                this.dataForm.createTime = data.apply.createTime
                this.dataForm.updateTime = data.apply.updateTime
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/order/apply/${!this.dataForm.id ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'id': this.dataForm.id || undefined,
                'applyUserId': this.dataForm.applyUserId,
                'idCard': this.dataForm.idCard,
                'idCardFrontImage': this.dataForm.idCardFrontImage,
                'idCardBackImage': this.dataForm.idCardBackImage,
                'driverLicenseImage': this.dataForm.driverLicenseImage,
                'licensePlate': this.dataForm.licensePlate,
                'color': this.dataForm.color,
                'description': this.dataForm.description,
                'carImages': this.dataForm.carImages,
                'status': this.dataForm.status,
                'approvalUserId': this.dataForm.approvalUserId,
                'approvalUserTrueName': this.dataForm.approvalUserTrueName,
                'noPassReason': this.dataForm.noPassReason,
                'createTime': this.dataForm.createTime,
                'updateTime': this.dataForm.updateTime
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
